package com.ipt.frm.pw;

import java.io.IOException;
import java.text.MessageFormat;
import java.util.Properties;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ipt.frm.beans.Mensaje;
import com.ipt.frm.enumeraciones.TipoMensaje;

/**
 * Servlet implementation class LogoutServlet
 */
public class LogoutServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	private static Properties propertiesMsg = null;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public LogoutServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	@Override
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		propertiesMsg = (Properties) getServletContext().getAttribute(
				"mensajes");
	}

	@Override
	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		Mensaje msg = new Mensaje(TipoMensaje.EXITO, MessageFormat.format(
				propertiesMsg.getProperty("logout.success"), request
						.getSession().getAttribute("username")));
		HttpSession session = request.getSession();
		session.invalidate();
		request.setAttribute("MSG", msg);
		request.setAttribute("titulo", "Login");
		request.getRequestDispatcher("login.jsp").forward(request, response);
	}
}
